package com.mrjy.coursepackage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.CoursePackageVideoRel;
import com.mrjy.common.entity.CoursePackageVip;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.coursepackage.bo.ICoursePackageVideoRelBo;
import com.mrjy.coursepackage.dto.CoursePackageVideoRelDTO;
import com.mrjy.maintain.util.RoleInfoEnum;
/**
 * 课程包基本信息 控制器
 * @author csshui
 *
 */
@Controller
@RequestMapping("/coursepackage/coursePackageVideoRel")
public class CoursePackageVideoRelController {
	
	
	@Resource
	private ICoursePackageVideoRelBo coursePackageVideoRelBo;
	
	/**
	 * 新增课程包数据
	 * @return
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public Object insert(CoursePackageVideoRel info){
		return coursePackageVideoRelBo.txInsert(info);
	}
	/**
	 * 根据id更新
	 * @param info
	 * @return
	 */
	@RequestMapping("/updateById")
	@ResponseBody
	public Object updateById(CoursePackageVideoRel info){
		return coursePackageVideoRelBo.txUpdateById(info);
	}
	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("/selectById")
	@ResponseBody
	public Object selectById(Integer id){
		return coursePackageVideoRelBo.selectById(id);
	}
	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(Integer id){
		return coursePackageVideoRelBo.txDelete(id);
	}
	/**
	 * 批量删除
	 * @param ids
	 * @param session
	 * @return
	 */
	@RequestMapping("/deleteByIds")
	@ResponseBody
	public Object deleteByIds(int[] ids, HttpSession session) {
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if (userInfo.getRoleId().intValue() == RoleInfoEnum.SYS_ADMIN.getRoleId() 
				|| userInfo.getRoleId().intValue() == RoleInfoEnum.VIDEO_ADMIN.getRoleId()) {
			return coursePackageVideoRelBo.txDeleteByIds(ids);
		} else {
			return "Forbidden";
		}
	}
	/**
	 * 批量新增视频 
	 * @return
	 */
	@RequestMapping("/insertVideos")
	@ResponseBody
	public Object insertVideos(CoursePackageVideoRelDTO dto){
		return coursePackageVideoRelBo.txInsertVideos(dto);
	}
	
	/**
	 * 增加
	 * @return
	 */
	@RequestMapping("/selectPage")
	@ResponseBody
	public Object selectPage(CoursePackageVideoRelDTO dto){
		return coursePackageVideoRelBo.selectPage(dto);
	}
	
	/**
	 * 根据课程包id和视频id查询视频主讲人的信息
	 * @return
	 */
	@RequestMapping("/selectByCoursePackageIdAndVideoId")
	@ResponseBody
	public Object selectByCoursePackageIdAndVideoId(CoursePackageVideoRelDTO dto){
		return coursePackageVideoRelBo.selectByCoursePackageIdAndVideoId(dto);
	}
	
	/**
	 * 根据视频id查询课程包信息
	 * info.videoId
	 * @return
	 */
	@RequestMapping("/selectCoursePackageByVideoId")
	@ResponseBody
	public Object selectCoursePackageByVideoId(CoursePackageVideoRelDTO dto , HttpSession session){
		UserInfo info = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		return coursePackageVideoRelBo.selectCoursePackageByVideoId(dto,info);
	}
	
}
